﻿using Microsoft.SemanticKernel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PluginDemo;

public class WeatherInformationPlugin : IDisposable
{
    private readonly HttpClient client;
    public WeatherInformationPlugin()
    {
        this.client = new HttpClient();
    }

    /// <summary>
    /// 获取指定的城市今天天气
    /// </summary>
    /// <param name="city"></param>
    /// <returns></returns>
    [KernelFunction, Description("获取指定的城市今天天气。")]
    public async Task<string> GetCityWeather([Description("指定的城市")] string city)
    {
        string url = $"https://api.seniverse.com/v3/weather/now.json?key=Sqpry1KJQJthbjV6L&location={city}&language=zh-Hans&unit=c";
        var response = await client.GetAsync(url);
        var content = await response.Content.ReadAsStringAsync();
        return content;
    }
    public void Dispose()
    {
        client.Dispose();
    }
}
